﻿
<!--
https://github.com/netnr
https://gitee.com/netnr
https://www.netnr.com
https://zme.ink
-->


<!DOCTYPE html>
<html>
<head>

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' />


    <title>加密转码 脚本服务</title>

    <meta name="keywords" content="netnr NET牛人 加密转码" />
    <meta name="description" content="Script Services 加密、解密、编码、转码" />

</head>
<body>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css' rel='stylesheet' />
<link href='https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css' rel='stylesheet' />
<script src='https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/jzjs@2.0.2/2.0.2/jz.min.js'></script>
<link href='https://cdn.jsdelivr.net/gh/netnr/cdn/libs/netnr-nav/1.1.2/netnrnav.css' rel='stylesheet' />
<script src='https://cdn.jsdelivr.net/gh/netnr/cdn/libs/netnr-nav/1.1.2/netnrnav.js' defer async></script>
        <link href="/css/global.css?v=NAI_hOr6ZSg5NjaPo94olMdf7kAXXyp9gYOiuK69lLE" rel="stylesheet" />
        <script src="/js/global.js?v=-UUx_lkaONxBXMxYH5RB2QtqMLBOuqV077SxjKI08E4"></script>
            <!--导航-->
            <button type="button" class="MenuToggle show-in-mobile btn btn-lg btn-warning ml-3 mt-3">
                <span class="fa fa-align-justify"></span>
            </button>
            <div class="netnrnav horizontal">
                <div class="netnrnav-wrapper">
                    <ul>
                        <li><a href="https://www.netnr.com" class="siteIcon"><img src="/favicon.ico" /> 首页</a></li>
                        <li><a href="https://www.netnr.com/gist/discover" title="代码片段"><span class="fa fa-fw fa-file-code-o"></span> Gist</a></li>
                        <li><a href="https://www.netnr.com/run/discover" title="在线运行代码"><span class="fa fa-fw fa-play"></span> Run</a></li>
                        <li><a href="https://www.netnr.com/doc" title="文档管理"><span class="fa fa-fw fa-book"></span> Doc</a></li>
                        <li><a href="https://www.netnr.com/draw/discover" title="绘制"><span class="fa fa-fw fa-paint-brush"></span> Draw</a></li>
                        <li><a href="/" title="ss.js.org"><span class="fa fa-fw fa-wrench"></span> 服务</a></li>
                        <li style="background-image: radial-gradient(ellipse, white, rgb(227, 248, 240))">
                            <!--标题-->
                                <a href='javascript:location.reload(false)' title="加密、解密、编码、转码">
                                    <svg class="titleicon"><use xlink:href="#lock"></use></svg> &#x52A0;&#x5BC6;&#x8F6C;&#x7801;
                                </a>
                        </li>
                        <li>
                            <a class="text-muted"><span class="fa fa-fw fa-ellipsis-h"></span></a>
                            <ul>
                                <li><a target="_blank" title="码云" href="https://gitee.com/netnr"><i class="fa fa-fw fa-git"></i> Gitee <sup><i class="fa small fa-external-link"></i></sup></a></li>
                                <li><a target="_blank" title="GitHub" href="https://github.com/netnr"><i class="fa fa-fw fa-github"></i> GitHub <sup><i class="fa small fa-external-link"></i></sup></a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        <div class="min300 mt-3">
            <style>
    .tab-pane {
        border: 1px solid #ddd;
        border-top: none;
    }
</style>

<div class="container-fluid">
    <div class="row">
        <div class="col-md-6 mb-3">
            <textarea class="form-control" id="txtCode1" rows="6" autofocus>一二12ab</textarea>
        </div>
        <div class="col-md-6 mb-3">
            <textarea class="form-control" rows="6" id="txtCode2"></textarea>
        </div>
    </div>

    <div class="row" title="散列/哈希">
        <div class="col-md-12">
            <hr />
            <div class="btn-group">
                <button class="btn btn-success">MD5</button>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-success">SHA1</button>
                <button type="button" class="btn btn-outline-secondary">224</button>
                <button type="button" class="btn btn-outline-secondary">256</button>
                <button type="button" class="btn btn-outline-secondary">384</button>
                <button type="button" class="btn btn-outline-secondary">512</button>
            </div>
        </div>
        <div class="col-md-12">
            <hr />
            <div class="btn-group">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <span class="input-group-text">密钥</span>
                    </div>
                    <input type="text" class="form-control" id="txtKey2" placeholder="HmacSHA、HmacMD5密钥">
                </div>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-success">HmacSHA1</button>
                <button type="button" class="btn btn-outline-secondary">224</button>
                <button type="button" class="btn btn-outline-secondary">256</button>
                <button type="button" class="btn btn-outline-secondary">384</button>
                <button type="button" class="btn btn-outline-secondary">512</button>
                <button type="button" class="btn btn-outline-secondary">HmacMD5</button>
            </div>
        </div>
    </div>

    <div class="row" title="加密/解密">
        <div class="col-md-12">
            <hr />
            <div class="btn-group">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <span class="input-group-text">密钥</span>
                    </div>
                    <input type="text" class="form-control" id="txtKey1" placeholder="请输入密钥">
                </div>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-warning">AES</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-warning">DES</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-warning">RC4</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-warning">Rabbit</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-warning">TripleDES</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
        </div>
    </div>

    <div class="row" title="编码转换">
        <div class="col-md-12">
            <hr />
            <div class="btn-group">
                <button type="button" class="btn btn-info">Base64</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-info">encodeURI</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-info">encodeURIComponent</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-info">Unicode</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-info">ASCII</button>
                <button type="button" class="btn btn-outline-secondary"><i class="fa fa-rotate-left"></i></button>
            </div>
        </div>
    </div>

    <div class="row" title="其他">
        <div class="col-md-12 mb-3">
            <hr />
            <div class="btn-group">
                <button type="button" class="btn btn-dark">UUID</button>
            </div>
        </div>
    </div>
</div>

<script src='https://cdn.jsdelivr.net/npm/crypto-js@4.0.0/crypto-js.min.js'></script>


<script>
    var t1 = $('#txtCode1'), t2 = $('#txtCode2'), k1 = $('#txtKey1'), k2 = $('#txtKey2');

    //按钮点击事件
    $(document.body).click(function (e) {
        e = e || window.event;
        var target = e.target || e.srcElement;
        if (target.nodeName == "BUTTON" || target.nodeName == "I") {
            var html = target.innerHTML;
            if (html == "" || html.indexOf("fa-rotate-left") >= 0) {
                html = "<I>"; target = target.nodeName == "I" ? $(target).parent() : $(target);
            } else {
                target = $(target);
            }

            switch (html) {
                //反向
                case "<I>":
                    var prevhtml = target.prev().html();
                    switch (prevhtml) {
                        case "AES":
                        case "DES":
                        case "RC4":
                        case "Rabbit":
                        case "TripleDES":
                            try {
                                t1.val(CryptoJS[prevhtml].decrypt(t2.val(), k1.val()).toString(CryptoJS.enc.Utf8));
                            } catch (e) {
                                t1.val('');
                            }
                            break;
                        case "encodeURI":
                            t1.val(decodeURI(t2.val()));
                            break;
                        case "encodeURIComponent":
                            t1.val(decodeURIComponent(t2.val()));
                            break;
                        case "Base64":
                            try {
                                t1.val(CryptoJS.enc.Base64.parse(t2.val()).toString(CryptoJS.enc.Utf8));
                            } catch (e) {
                                t1.val('')
                            }
                            break;
                        case "Unicode":
                            try { t1.val(UnConvertUnicode(t2.val())); } catch (e) { t1.val('') }
                            break;
                        case "ASCII":
                            try { t1.val(UnConvertAscii(t2.val())); } catch (e) { t1.val('') }
                            break;
                    }
                    break;

                case "AES":
                case "DES":
                case "RC4":
                case "Rabbit":
                case "TripleDES":
                    try { t2.val(CryptoJS[html].encrypt(t1.val(), k1.val())); } catch (e) { t2.val(''); }
                    break;

                case "MD5":
                    var s1 = t1.val(), s2 = CryptoJS.MD5(t1.val()).toString(), s3 = s2.substr(8, 16);
                    t2.val("源字符串：" + s1 + "\n16位小写：" + s3 + "\n16位大写：" + s3.toUpperCase() + "\n32位小写：" + s2 + "\n32位大写：" + s2.toUpperCase());
                    break;
                case "SHA1":
                case "HmacSHA1":
                case "224":
                case "256":
                case "384":
                case "512":
                case "HmacMD5":
                    var cmdN = html;
                    if (target.parent().children().first().html() == "SHA1") {
                        cmdN.length == 3 && (cmdN = "SHA" + cmdN);
                        try { t2.val(CryptoJS[cmdN](t1.val())); } catch (e) { t2.val(''); }
                    } else {
                        cmdN.length == 3 && (cmdN = "HmacSHA" + cmdN);
                        try { t2.val(CryptoJS[cmdN](t1.val(), k2.val())); } catch (e) { t2.val(''); }
                    }
                    break;

                case "encodeURI":
                    t2.val(encodeURI(t1.val()));
                    break;
                case "encodeURIComponent":
                    t2.val(encodeURIComponent(t1.val()));
                    break;
                case "Base64":
                    try { t2.val(CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(t1.val()))); } catch (e) { t2.val('') }
                    break;
                case "Unicode":
                    t2.val(ConvertUnicode(t1.val()));
                    break;
                case "ASCII":
                    t2.val(ConvertAscii(t1.val()));
                    break;

                case "UUID":
                    t2.val("Loading ...");
                    $.ajax({
                        url: `${ss.apiServer}/uuid/6`,
                        dataType: 'json',
                        success: function (data) {
                            t2.val(data.join('\r\n'));
                        },
                        error: function () {
                            t2.val('生成UUID失败');
                        }
                    });
                    break;
            }
        }
    });

    //转码 To Unicode
    function ConvertUnicode(s) {
        var val = "", i = 0, c, len = s.length;
        for (; i < len; i++) {
            c = s.charCodeAt(i).toString(16);
            while (c.length < 4) { c = '0' + c; } val += '\\u' + c
        } return val
    };

    //转码 Unicode To STR-CN
    function UnConvertUnicode(s) { return eval("'" + s + "'"); };/*return unescape(str.replace(/\u/g, "%u"))*/

    //转码 To ASCII
    function ConvertAscii(s) {
        var val = "", i = 0, len = s.length;
        for (; i < len; i++) { val += "&#" + s[i].charCodeAt() + ";"; }
        return val
    };

    //转码 ASCII To STR-CN
    function UnConvertAscii(s) {
        var val = "", strs = s.match(/&#(\d+);/g);
        if (strs != null) {
            for (var i = 0, len = strs.length; i < len; i++) {
                val += String.fromCharCode(strs[i].replace(/[&#;]/g, ''));
            }
        } return val
    };
</script>
        </div>
            <a href="javascript:ss.toTop();" class="totop" title="返回顶部">ˆ</a>
</body>
</html>
